package com.example.student.controller;

import com.example.student.utils.UserUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.example.student.utils.ResultBody;
import com.example.student.config.PageParam;
import com.example.student.service.ActivityCollectionService;
import com.example.student.entity.ActivityCollection;


/**
 * 活动收藏记录 控制器
 * @author lx
 */
@RestController
@RequestMapping(value = "activityCollection")
public class ActivityCollectionController {
       @Resource
       public ActivityCollectionService service;

       /**
        * 新增
        * @param activityCollection
        */
       @PostMapping("/add")
       public ResultBody add(@RequestBody ActivityCollection activityCollection){
            this.service.add(activityCollection);
            return ResultBody.success("添加成功");
        }

       /**
        * 修改
        * @param activityCollection
        */
       @PostMapping("/update")
       public ResultBody update(@RequestBody ActivityCollection activityCollection){
            this.service.update(activityCollection);
            return ResultBody.success("修改成功");
        }

        /**
         * 查找
         * @param id
         */
        @GetMapping("/getOne")
        public ResultBody getOne(String id){
            ActivityCollection obj=this.service.getOne(id);
            if(obj!=null){
                return ResultBody.success(obj);
            }else{
                return ResultBody.error("未获取到数据!");
            }
        }

        /**
        * 删除单条
        * @param activityCollection
        */
        @PostMapping("/delete")
        public ResultBody delete(@RequestBody ActivityCollection  activityCollection){
            this.service.delete(activityCollection.getId());
            return ResultBody.success("删除成功");
        }

        /**
         * 删除多条
         * @param ids
         */
        @PostMapping("/deleteByIds")
        public ResultBody deleteByIds(@RequestBody String[]  ids){
            this.service.deleteByIds(ids);
            return ResultBody.success("删除成功");
        }

        /**
         * 列表查询
         * @param pageParam
         * @return
         */
        @PostMapping(value = "/page")
        public ResultBody page(@RequestBody PageParam pageParam){
            pageParam.getParam().put("userId", UserUtils.getId());
            return ResultBody.success(this.service.page(pageParam));
        }
}
